home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / pleas / ole / visio / search / frmsearc.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-05-18  |  17.6 KB  |  503 lines

  1. VERSION 2.00
  2. Begin Form frmSearchReplace 
  3.    BackColor       =   &H00E0FFFF&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Search / Replace"
  6.    ClientHeight    =   4680
  7.    ClientLeft      =   1425
  8.    ClientTop       =   1605
  9.    ClientWidth     =   5055
  10.    FillColor       =   &H00E0FFFF&
  11.    Height          =   5175
  12.    Left            =   1320
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   4680
  17.    ScaleWidth      =   5055
  18.    Top             =   1215
  19.    Width           =   5265
  20.    Begin CommandButton cmdCancel 
  21.       Cancel          =   -1  'True
  22.       Caption         =   "Cancel"
  23.       Height          =   495
  24.       Left            =   2400
  25.       TabIndex        =   18
  26.       Top             =   3840
  27.       Width           =   1215
  28.    End
  29.    Begin CommandButton cmdOK 
  30.       Caption         =   "OK"
  31.       Height          =   495
  32.       Left            =   3720
  33.       TabIndex        =   17
  34.       Top             =   3840
  35.       Width           =   1215
  36.    End
  37.    Begin TextBox txtReplaceBy 
  38.       Height          =   285
  39.       Left            =   1320
  40.       TabIndex        =   2
  41.       Top             =   720
  42.       Width           =   3615
  43.    End
  44.    Begin TextBox txtSearchFor 
  45.       Height          =   285
  46.       Left            =   1320
  47.       TabIndex        =   1
  48.       Top             =   240
  49.       Width           =   3615
  50.    End
  51.    Begin Frame Frame2 
  52.       BackColor       =   &H00E0FFFF&
  53.       Caption         =   "Fields to Change"
  54.       Height          =   3255
  55.       Left            =   240
  56.       TabIndex        =   6
  57.       Top             =   1080
  58.       Width           =   1995
  59.       Begin CheckBox DoSize 
  60.          BackColor       =   &H00E0FFFF&
  61.          Caption         =   "Text Size"
  62.          Height          =   375
  63.          Left            =   480
  64.          TabIndex        =   8
  65.          Top             =   960
  66.          Width           =   1200
  67.       End
  68.       Begin CheckBox DoData3 
  69.          BackColor       =   &H00E0FFFF&
  70.          Caption         =   "Data 3"
  71.          Height          =   375
  72.          Left            =   480
  73.          TabIndex        =   12
  74.          Top             =   2760
  75.          Width           =   1000
  76.       End
  77.       Begin CheckBox DoData2 
  78.          BackColor       =   &H00E0FFFF&
  79.          Caption         =   "Data 2"
  80.          Height          =   375
  81.          Left            =   480
  82.          TabIndex        =   11
  83.          Top             =   2400
  84.          Width           =   1000
  85.       End
  86.       Begin CheckBox DoData1 
  87.          BackColor       =   &H00E0FFFF&
  88.          Caption         =   "Data 1"
  89.          Height          =   375
  90.          Left            =   480
  91.          TabIndex        =   10
  92.          Top             =   2040
  93.          Width           =   1000
  94.       End
  95.       Begin CheckBox DoName 
  96.          BackColor       =   &H00E0FFFF&
  97.          Caption         =   "Name"
  98.          Height          =   375
  99.          Left            =   480
  100.          TabIndex        =   9
  101.          Top             =   1680
  102.          Width           =   1000
  103.       End
  104.       Begin CheckBox DoText 
  105.          BackColor       =   &H00E0FFFF&
  106.          Caption         =   "Text"
  107.          Height          =   375
  108.          Left            =   480
  109.          TabIndex        =   7
  110.          Top             =   600
  111.          Value           =   1  'Checked
  112.          Width           =   1200
  113.       End
  114.       Begin Label Label2 
  115.          BackColor       =   &H00E0FFFF&
  116.          Caption         =   "The Text"
  117.          Height          =   255
  118.          Left            =   120
  119.          TabIndex        =   14
  120.          Top             =   360
  121.          Width           =   1200
  122.       End
  123.       Begin Label Label1 
  124.          BackColor       =   &H00E0FFFF&
  125.          Caption         =   "Special Fields"
  126.          Height          =   255
  127.          Left            =   120
  128.          TabIndex        =   13
  129.          Top             =   1440
  130.          Width           =   1500
  131.       End
  132.    End
  133.    Begin Frame Frame1 
  134.       BackColor       =   &H00E0FFFF&
  135.       Caption         =   "Scope of Search"
  136.       Height          =   1575
  137.       Left            =   2640
  138.       TabIndex        =   0
  139.       Top             =   1200
  140.       Width           =   1995
  141.       Begin OptionButton optScope 
  142.          BackColor       =   &H00E0FFFF&
  143.          Caption         =   "All Pages"
  144.          Height          =   375
  145.          Index           =   2
  146.          Left            =   240
  147.          TabIndex        =   5
  148.          Top             =   1080
  149.          Width           =   1455
  150.       End
  151.       Begin OptionButton optScope 
  152.          BackColor       =   &H00E0FFFF&
  153.          Caption         =   "Current Page"
  154.          Height          =   375
  155.          Index           =   1
  156.          Left            =   240
  157.          TabIndex        =   4
  158.          Top             =   720
  159.          Width           =   1455
  160.       End
  161.       Begin OptionButton optScope 
  162.          BackColor       =   &H00E0FFFF&
  163.          Caption         =   "Selection"
  164.          Enabled         =   0   'False
  165.          Height          =   375
  166.          Index           =   0
  167.          Left            =   240
  168.          TabIndex        =   3
  169.          Top             =   360
  170.          Width           =   1335
  171.       End
  172.    End
  173.    Begin Label lblPassiveHelp 
  174.       BackColor       =   &H00FFC0C0&
  175.       BorderStyle     =   1  'Fixed Single
  176.       Height          =   255
  177.       Left            =   0
  178.       TabIndex        =   20
  179.       Top             =   4440
  180.       Width           =   5055
  181.    End
  182.    Begin Label Label5 
  183.       Caption         =   "     Search/Replace for Visio.                           Version 1.1                                   Copyright (c) 1993                     by Dennis K. Fitzgerald"
  184.       FontBold        =   0   'False
  185.       FontItalic      =   0   'False
  186.       FontName        =   "MS Serif"
  187.       FontSize        =   8.25
  188.       FontStrikethru  =   0   'False
  189.       FontUnderline   =   0   'False
  190.       Height          =   855
  191.       Left            =   2640
  192.       TabIndex        =   19
  193.       Top             =   2880
  194.       Width           =   1935
  195.       WordWrap        =   -1  'True
  196.    End
  197.    Begin Label Label4 
  198.       BackColor       =   &H00E0FFFF&
  199.       Caption         =   "Replace By:"
  200.       Height          =   285
  201.       Left            =   240
  202.       TabIndex        =   16
  203.       Top             =   720
  204.       Width           =   1095
  205.    End
  206.    Begin Label Label3 
  207.       BackColor       =   &H00E0FFFF&
  208.       Caption         =   "Search For:"
  209.       Height          =   285
  210.       Left            =   240
  211.       TabIndex        =   15
  212.       Top             =   240
  213.       Width           =   1095
  214.    End
  215. Sub cmdCancel_Click ()
  216.   End                   'Close everything and go home
  217. End Sub
  218. Sub cmdCancel_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  219.   HelpOn "Click to cancel and return to Visio."
  220. End Sub
  221. Sub cmdOK_Click ()
  222. '   Make sure there is something to search for
  223.   If txtSearchFor = "" Then
  224.     Beep
  225.     MsgBox "You must specify ""Search For:"" text.", 48, "Visio Search/Replace"
  226.     txtSearchFor.SetFocus
  227.     Exit Sub
  228.   End If
  229. '   Make sure a Field to Change has been specified
  230.   If DoText + DoSize + DoName + DoData1 + DoData2 + DoData3 = 0 Then
  231.     Beep
  232.     MsgBox "You must select one or more Fields to Change.", 48, "Visio Search/Replace"
  233.     DoText.SetFocus
  234.     Exit Sub
  235.   End If
  236. '   When changing size, check for valid replace-by
  237.   If DoSize Then
  238.     If Val(txtReplaceBy) <= 0 Then
  239.       Beep
  240.       MsgBox ("When changing size, Replace By must be numeric and greater than zero.")
  241.       txtReplaceBy.SetFocus
  242.       Exit Sub
  243.     End If
  244.   End If
  245. '   Start the search
  246.   Select Case ScopeSelection
  247.   Case 0    'Selection
  248.     frmConfirm!lblSearching = "Selection"
  249.     DoSearch SelList
  250.   Case 1    'Current Page
  251.     Set Curpage = appVisio.ActivePage
  252.     If Curpage Is Nothing Then
  253.       Beep
  254.       MsgBox "There is no current page.", 16, "Visio Search/Replace"
  255.       End
  256.     End If
  257.     Debug.Print "Processing current page named "; Curpage.Name
  258.     Set ShapeList = Curpage.Shapes
  259.     frmConfirm!lblSearching = "Page: " & Curpage.Name
  260.     DoSearch ShapeList
  261.   Case 2    'All pages
  262.     Set PageList = doc.Pages
  263.     npages = PageList.Count
  264.     If npages = 0 Then
  265.       Beep
  266.       MsgBox "There are no pages.", 16, "Visio Search/Replace"
  267.       End
  268.     End If
  269.     For i = 1 To npages
  270.       Set Curpage = PageList(i)
  271.       Debug.Print "Processing page "; i; " named "; Curpage.Name
  272.       Set ShapeList = Curpage.Shapes
  273.       frmConfirm!lblSearching = "Page: " & Curpage.Name
  274.       DoSearch ShapeList
  275.     Next i
  276.   End Select
  277. End Sub
  278. Sub cmdOK_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  279.   HelpOn "Click to start Search/Replace."
  280. End Sub
  281. Sub DoData1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  282.   HelpOn "Select (X) to search and replace in Data1 field."
  283. End Sub
  284. Sub DoData2_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  285.   HelpOn "Select (X) to search and replace in Data2 field."
  286. End Sub
  287. Sub DoData3_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  288.   HelpOn "Select (X) to search and replace in Data3 field."
  289. End Sub
  290. Sub DoName_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  291.   HelpOn "Select (X) to search and replace in Name field."
  292. End Sub
  293. Sub DoSearch (ShapeList As Object)
  294. '   This is the guts of Visio Search Replace
  295. '   DoSearch does the actual search and replace using
  296. '   ShapeList as the collection of shapes to process.
  297. '----------------------------------------------------------
  298. '   Initialize FindMode to srSkip so Confirmation Form
  299. '   will be called on first match.
  300.   FindMode = srSkip
  301. '   Loop through shapes in ShapeList
  302.   nshapes = ShapeList.Count
  303.   Debug.Print "DoSearch called.  nshapes="; nshapes
  304.   If nshapes > 0 Then
  305.     For i = 1 To nshapes
  306.       Set CurShape = ShapeList.Item(i)          'Get next shape
  307.       frmConfirm!lblInShape = CurShape.Name     'Fill in shape name in Confirmation form
  308.       Debug.Print "Found shape "; CurShape.Name
  309. '   Process Text Field
  310.       If DoText Then                      'Is text field specified?
  311.         Debug.Print "Processing Text: "; CurShape.Text
  312.         ii = InStr(1, CurShape.Text, txtSearchFor)  'search for text
  313.         If ii <> 0 Then  'found
  314.           If FindMode <> srDoAll Then
  315.             frmConfirm!lblInField = "Text"
  316.             frmConfirm!lblFoundTxt = CurShape.Text
  317.             frmConfirm.Show 1
  318.           End If
  319.           If FindMode <> srSkip Then
  320.             newstr$ = Mid$(CurShape.Text, 1, ii - 1) & txtReplaceBy & Mid$(CurShape.Text, ii + Len(txtSearchFor))
  321.             Debug.Print "Newstr="; newstr$
  322.             CurShape.Text = newstr$
  323.           End If
  324.         End If
  325.       End If
  326.       If DoSize Then
  327.         Set CurCell = CurShape.CellsSRC(visSectionCharacter, visRowCharacter, visCharacterSize)
  328.         CurSize = CurCell.Result(visPoints)
  329.         Debug.Print "Processing Size: "; CurSize
  330.         If CurSize = Val(txtSearchFor) Then  'found
  331.           If FindMode <> srDoAll Then
  332.             frmConfirm!lblInField = "Text Size in Points"
  333.             frmConfirm!lblFoundTxt = CurSize
  334.             frmConfirm.Show 1
  335.           End If
  336.           If FindMode <> srSkip Then
  337.             If Val(txtReplaceBy) > 0 Then
  338.               CurCell.Result(visPoints) = Val(txtReplaceBy)
  339.             End If
  340.           End If
  341.         End If
  342.       End If
  343. '   Process Name Field
  344.       If DoName Then                      'Is Name field specified?
  345.         Debug.Print "Processing Name: "; CurShape.Name
  346.         ii = InStr(1, CurShape.Name, txtSearchFor)  'search for text
  347.         If ii <> 0 Then  'found
  348.           If FindMode <> srDoAll Then
  349.             frmConfirm!lblInField = "Name"
  350.             frmConfirm!lblFoundTxt = CurShape.Name
  351.             frmConfirm.Show 1
  352.           End If
  353.           If FindMode <> srSkip Then
  354.             newstr$ = Mid$(CurShape.Name, 1, ii - 1) & txtReplaceBy & Mid$(CurShape.Name, ii + Len(txtSearchFor))
  355.             Debug.Print "Newstr="; newstr$
  356.             CurShape.Name = newstr$
  357.           End If
  358.         End If
  359.       End If
  360. '   Process Data1 field
  361.       If DoData1 Then
  362.         Debug.Print "Processing Data1: "; CurShape.Data1
  363.         ii = InStr(1, CurShape.Data1, txtSearchFor)
  364.         If ii <> 0 Then  'found
  365.           If FindMode <> srDoAll Then
  366.             frmConfirm!lblInField = "Data1"
  367.             frmConfirm!lblFoundTxt = CurShape.Data1
  368.             frmConfirm.Show 1
  369.           End If
  370.           If FindMode <> srSkip Then
  371.             newstr$ = Mid$(CurShape.Data1, 1, ii - 1) & txtReplaceBy & Mid$(CurShape.Data1, ii + Len(txtSearchFor))
  372.             Debug.Print "Newstr="; newstr$
  373.             CurShape.Data1 = newstr$
  374.           End If
  375.         End If
  376.       End If
  377. '   Process Data2 field
  378.       If DoData2 Then
  379.         Debug.Print "Processing Data2: "; CurShape.Data2
  380.         ii = InStr(1, CurShape.Data2, txtSearchFor)
  381.         If ii <> 0 Then  'found
  382.           If FindMode <> srDoAll Then
  383.             frmConfirm!lblInField = "Data2"
  384.             frmConfirm!lblFoundTxt = CurShape.Data2
  385.             frmConfirm.Show 1
  386.           End If
  387.           If FindMode <> srSkip Then
  388.             newstr$ = Mid$(CurShape.Data2, 1, ii - 1) & txtReplaceBy & Mid$(CurShape.Data2, ii + Len(txtSearchFor))
  389.             Debug.Print "Newstr="; newstr$
  390.             CurShape.Data2 = newstr$
  391.           End If
  392.         End If
  393.       End If
  394. '   Process Data3 field
  395.       If DoData3 Then
  396.         Debug.Print "Processing Data3: "; CurShape.Data3
  397.         ii = InStr(1, CurShape.Data3, txtSearchFor)
  398.         If ii <> 0 Then  'found
  399.           If FindMode <> srDoAll Then
  400.             frmConfirm!lblInField = "Data3"
  401.             frmConfirm!lblFoundTxt = CurShape.Data3
  402.             frmConfirm.Show 1
  403.           End If
  404.           If FindMode <> srSkip Then
  405.             newstr$ = Mid$(CurShape.Data3, 1, ii - 1) & txtReplaceBy & Mid$(CurShape.Data3, ii + Len(txtSearchFor))
  406.             Debug.Print "Newstr="; newstr$
  407.             CurShape.Data3 = newstr$
  408.           End If
  409.         End If
  410.       End If
  411.     Next i
  412.   End If
  413. End Sub
  414. Sub DoSize_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  415.   HelpOn "Select (X) to search and replace in Character Size field."
  416. End Sub
  417. Sub DoText_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  418.   HelpOn "Select (X) to search and replace in Text field."
  419. End Sub
  420. Sub Form_Load ()
  421. '   Link up with Visio application, if any
  422.   On Error GoTo NoVisio                           ' Don't blow up if no Visio
  423.   Set appVisio = GetObject(, "visio.application") ' Get Visio instance
  424.   On Error GoTo 0                                 ' OK to blow up, now.
  425. '   Get current document
  426.   If appVisio.Documents.Count > 0 Then
  427.     Set doc = appVisio.ActiveDocument
  428.     Debug.Print "Current Document is "; doc.Name
  429.   Else
  430.     Beep
  431.     MsgBox "There are no open Visio documents.", 16, "Visio Search/Replace"
  432.     End
  433.   End If
  434. '   Get current window and check to see if there is a selection
  435.   Set CurWin = appVisio.ActiveWindow
  436.   If CurWin Is Nothing Or CurWin.Type <> visDrawing Then
  437.     Beep
  438.     MsgBox "There is no active Visio drawing window.", 16, "Visio Search/Replace"
  439.     End
  440.   End If
  441.   Set SelList = CurWin.Selection
  442.   SelCount = SelList.Count
  443.   If SelCount = 0 Then
  444.     optScope(0).Enabled = False
  445.     optScope(1).Value = True   'Default to Current Page
  446.   Else
  447.     optScope(0).Enabled = True
  448.     optScope(0).Value = True  'Default to Selection
  449.   End If
  450. Exit Sub
  451. '   Come here when we get error accessing Visio
  452. NoVisio:
  453.   Beep
  454.   MsgBox "Visio is not active", 16, "Visio Search/Replace"
  455.   End
  456. End Sub
  457. Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  458.   HelpOff
  459. End Sub
  460. Sub Frame1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  461.   HelpOn "Select which collection of shapes to process."
  462. End Sub
  463. Sub Frame2_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  464.   HelpOn "Select field(s) to search."
  465. End Sub
  466. Sub HelpOff ()
  467.   lblPassiveHelp = ""
  468. End Sub
  469. Sub HelpOn (t)
  470.    lblPassiveHelp = t
  471. End Sub
  472. Sub Label1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  473.   HelpOff
  474. End Sub
  475. Sub Label2_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  476.   HelpOff
  477. End Sub
  478. Sub Label3_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  479.   HelpOff
  480. End Sub
  481. Sub Label4_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  482.   HelpOff
  483. End Sub
  484. Sub Label5_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  485.   HelpOn "Hope you enjoy using Visio Search/Replace!"
  486. End Sub
  487. Sub lblPassiveHelp_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  488.   HelpOff
  489. End Sub
  490. Sub optScope_Click (Index As Integer)
  491.   Debug.Print "optScope.click called with Index="; Index
  492.   ScopeSelection = Index
  493. End Sub
  494. Sub optScope_MouseMove (Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  495.   HelpOn "Select which collection of shapes to process."
  496. End Sub
  497. Sub txtReplaceBy_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  498.   HelpOn "Enter replacement text."
  499. End Sub
  500. Sub txtSearchFor_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  501.   HelpOn "Enter text to search for."
  502. End Sub
  503.